package topic

import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('api/programs/\\d+/topicTask')), producer('api/programs/1/topicTask'))
        headers {
            contentType(applicationJsonUtf8())
        }
    }
    response {
        status 200
        body("""
            [{
              "topics": {
                "id": 1,
                "programId": 1,
                "title": "topic title",
                "createTime": "2016-09-09 00:00:00.0",
                "orderNumber": 1,
                "visible": true
              },
              "tasks": [
                {
                  "id": 1,
                  "programId": 1,
                  "visible": true,
                }
              ]
            }]
        """)
        bodyMatchers {
            jsonPath('$.[*]', byType())
            jsonPath('$.[*].topics.id', byRegex(number()))
            jsonPath('$.[*].topics.programId',byRegex(number()))
            jsonPath('$.[*].topics.title',byRegex(nonEmpty()))
            jsonPath('$.[*].topics.createTime',byRegex(nonEmpty()))
            jsonPath('$.[*].topics.orderNumber',byRegex(number()))
            jsonPath('$.[*].topics.visible',byRegex(anyBoolean()))
            jsonPath('$.[*].tasks.[*].id', byRegex(number()))
            jsonPath('$.[*].tasks.[*].programId', byRegex(number()))
            jsonPath('$.[*].tasks.[*].visible', byRegex(anyBoolean()))
        }
        headers {
            contentType(applicationJsonUtf8())
        }
    }
}